#include <iostream>
#include <cstring>

using namespace std;

typedef long long LL;
const int N = 1e5 + 10, M = 55;
const LL INF = -1e15;

LL n, q;
LL v[M], c[M];
LL f[N], m = N, w;

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

void circle()
{
	for(int i = 1; i < m; i++) f[i] = INF;
	for(int i = 1; i <= n; i++)
	{
		if(f[i] == m) continue;
		int d = gcd(v[i], m);
		for(int j = 0; j < d; j++)
			for(int x = j, cnt = 0; cnt < 2; cnt += (x == j))
			{
				int y = (x + v[i]) % m;
				if(f[x] != INF)
				f[y] = min(f[y], f[x] + c[i] - (v[i] + x) / m * w);
				x = y;
			}
	}
}

int main()
{
	cin >> n >> q;
	for(int i = 1; i <= n; i++)
	{
		cin >> v[i] >> c[i];
		if(w * v[i] < m * c[i]) 
		{
			w = c[i]; m = v[i];
		}
	}
	
	circle();
	
	while(q--)
	{
		LL V; cin >> V;
		LL t = V % m;
		if(f[t] == INF) cout << -1 << endl;
		else cout << (V / m * w + f[t]) << endl; 
	}
	
	return 0;
} 
